//-------------------------------------------------------------------------
// Copyright (c) 2000-2010 Digital. All Rights Reserved.
//
// This software is the confidential and proprietary information of
// Digital
//
// Original author: qingang
//
//-------------------------------------------------------------------------
// LOOSOFT MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
// THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE, OR NON-INFRINGEMENT. UFINITY SHALL NOT BE
// LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
// MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
//
// THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
// CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
// PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
// NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
// SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
// SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
// PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). UFINITY
// SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
// HIGH RISK ACTIVITIES.
//-------------------------------------------------------------------------
package com.gm.bamboo.web.manage;

import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import cn.common.lib.springside.web.CrudActionSupport;

import com.gm.bamboo.contant.Global;
import com.gm.bamboo.core.UserAuthManager;
import com.gm.bamboo.core.UserManager;
import com.gm.bamboo.entity.UserAuth;

/**
 * 会员中心权限action
 * 
 * @author qingang
 * @version 1.0
 * @since 2012-10-14
 */
@Namespace("/backend")
public class UserauthAction extends CrudActionSupport<UserAuth>
{
    /**
     * serialVersionUID long
     */
    private static final long serialVersionUID = 1L;

    private Long              userid;

    @Autowired
    private UserAuthManager   userAuthManager;

    @Autowired
    private UserManager       userManager;

    private UserAuth          userauth;

    /**
     * {@inheritDoc}
     * 
     * @since 2012-10-14
     * @see cn.common.lib.springside.web.CrudActionSupport#input()
     */
    @Override
    public String input() throws Exception
    {
        return SUCCESS;
    }

    @Override
    public String list() throws Exception
    {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * {@inheritDoc}
     * 
     * @since 2012-10-14
     * @see cn.common.lib.springside.web.CrudActionSupport#prepareModel()
     */
    @Override
    protected void prepareModel() throws Exception
    {

        if (userid != null)
        {
            userauth = userAuthManager.getUserAuth(userid);
            if (userauth == null)
            {
                userauth = new UserAuth();
                userauth.setUser(userManager.get(userid));
            }
        }
    }

    /**
     * {@inheritDoc}
     * 
     * @since 2012-10-14
     * @see cn.common.lib.springside.web.CrudActionSupport#save()
     */
    @Override
    public String save() throws Exception
    {
        try
        {
            userAuthManager.save(userauth);
            this.addActionMessage(Global.SAVE_SUCCESS);
        }
        catch (Exception e)
        {
            this.addActionMessage(Global.SAVE_LOSE);
            e.printStackTrace();
        }
        return SUCCESS;
    }

    /**
     * {@inheritDoc}
     * 
     * @since 2012-10-14
     * @see com.opensymphony.xwork2.ModelDriven#getModel()
     */
    @Override
    public UserAuth getModel()
    {
        return userauth;
    }

    public Long getUserid()
    {
        return userid;
    }

    public void setUserid(Long userid)
    {
        this.userid = userid;
    }

    public UserAuth getUserauth()
    {
        return userauth;
    }

    public void setUserauth(UserAuth userauth)
    {
        this.userauth = userauth;
    }

}
